package com.siyao.redvip.ui.adapter;

import java.util.ArrayList;
import java.util.List;
import com.siyao.redvip.R;
import com.siyao.redvip.bean.Record;
import com.siyao.redvip.components.view.LoadingDialog;
import com.siyao.redvip.components.view.MeasuredGridView;
import com.siyao.redvip.utils.ToastUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class HDetailsAdapter extends BaseAdapter {

	protected Context mContext;
	protected LoadingDialog pd;
	protected List<Record> list;
	private LayoutInflater mInflater;// 加载list_item
	
	List<String> listImageUrl;//存放地址

	public HDetailsAdapter(Context context) {
		 this.mContext = context;
	        pd = new LoadingDialog(mContext);
	        pd.setCancelable(false);
	        mInflater = LayoutInflater.from(context);
	}
	

	public void setList(List<Record> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.isEmpty() ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return position < 0 ? 0 : position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView=mInflater.inflate(R.layout.hdxx_list_item, null);
			viewHolder.userName = (TextView) convertView.findViewById(R.id.textview_username);
			viewHolder.gridView=(MeasuredGridView) convertView.findViewById(R.id.gv_imgs);
			convertView.setTag(viewHolder);
		} else {
			viewHolder=(ViewHolder) convertView.getTag();
		}
			Record  r= list.get(position);
			viewHolder.userName.setText(r.getName());
			MeasuredGridViewAdapter adapter = new MeasuredGridViewAdapter(mContext);
			String[] images=r.getImages().split(",");
			listImageUrl = new ArrayList<String>();
			for (int j = 0; j < images.length; j++) {
				listImageUrl.add(images[j]);
			}
			adapter.setDataUrl(listImageUrl);
			viewHolder.gridView.setAdapter(adapter);
		return convertView;
	}
	
	private static class ViewHolder {
		public TextView userName;
		public MeasuredGridView gridView;
	}
}
